/****************************************************************************
**
** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Quick Studio Components.
**
** $QT_BEGIN_LICENSE:GPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 or (at your option) any later version
** approved by the KDE Free Qt Foundation. The licenses are as published by
** the Free Software Foundation and appearing in the file LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

import QtQuick 2.15
import QtQuick.Window 2.15
import SutoDisplay 1.0
import QtQuick.VirtualKeyboard 2.15
import QtQuick.Controls 2.15
import TaoQuick 1.0
import QtQuick.VirtualKeyboard.Settings 2.2
import QtQuick.VirtualKeyboard.Styles 2.15

Item {
    width: (Screen.desktopAvailableWidth > 1024)?1024:Screen.desktopAvailableWidth
    height: (Screen.desktopAvailableHeight > 600)?600:Screen.desktopAvailableHeight
    state: "Mainwind"
    id:rootLoader0
    property int heightoffset: 0


    Component.onCompleted: {
        console.log(width+""+height)
    }


    Text{
        anchors.bottom: parent.bottom
        anchors.right: parent.right
        text: "Pix = "+Screen.desktopAvailableWidth +"x"+Screen.desktopAvailableHeight
    }

//    TitlePane{
//        id:titlepane
//        x:0
//        y:0
//        width: parent.width
//        height: 60
//    }
    Component{
        id:menubtn
        LogoButton{
            property bool ismain: true
            objectName: "menu"
            onClicked: {
                if(ismain === true){
                    mainpane.source = conPATH+"MenuForm.qml"
                    ismain = false
                }else{
                    mainpane.source = conPATH+"MainForm.qml"
                    ismain = true
                }
            }
        }
    }


    TitlePane{
        id:titlepane
        x:0
        y:0
        width: parent.width
        height: 60
        logobtn: menubtn

    }

    MainPane{
        id:mainpane
        width:parent.width
        height: parent.height - 60
        z:-1
        y:60+heightoffset
        Connections{
            target: inputPanel
            function onInpanelposition(posx,posy){
                if(inputPanel.showKeyboard === true){
                    if( InputContext.anchorRectangle.y+InputContext.anchorRectangle.height +60 > inputPanel.y ){
                        heightoffset = heightoffset-(InputContext.anchorRectangle.y+InputContext.anchorRectangle.height-inputPanel.y + 60)
                    }
                }else{
                     heightoffset = 0
                }
            }
        }
    }



//key board
//    Connections{
//        target: inputPanel
//        function onInpanelposition(posx,posy){
//            if(inputPanel.showKeyboard === true){
//                if( InputContext.anchorRectangle.y+InputContext.anchorRectangle.height > inputPanel.y ){
//                    y = y-(InputContext.anchorRectangle.y+InputContext.anchorRectangle.height-inputPanel.y + 60)
//                }
//            }else{
//                 y = 0
//            }
//        }
//    }

    InputPanel {
        id: inputPanel
        property bool showKeyboard :  active
        y: showKeyboard ? parent.height - height : parent.height

        signal isshowkeyboard(bool show)
        signal inpanelposition(int x,int y)

        onShowKeyboardChanged: {
            isshowkeyboard(showKeyboard)
        }

        onYChanged:{
            inpanelposition(x,y)
        }

        Behavior on y {
            NumberAnimation {
                duration: 200
                easing.type: Easing.InOutQuad
            }
        }
//        height: 283
        width: parent.width
        anchors.left: parent.left
        anchors.right: parent.right
        anchors.rightMargin: 0
        anchors.leftMargin: 0

    }

    Binding {
        target: VirtualKeyboardSettings
        property: "activeLocales"
        value: ["zh_CN","en_US"]
    }
    states: [
        State {
            name: "Mainwind"
            PropertyChanges {
                target: mainpane
                visible:true
            }
        },
        State {
            name: "Menu"
            PropertyChanges {
                  target: mainpane
                  visible:false
            }
        }
    ]




}


/*##^##
Designer {
    D{i:0;formeditorZoom:0.66}
}
##^##*/
